#ifndef SERIAL_H
#define SERIAL_H

#include <QObject>
#include<QtSerialPort/QSerialPort>
#include <QSerialPortInfo>

//#define IS_INSTANCE

class Serial : public QObject
{
    Q_OBJECT
public:
#ifdef IS_INSTANCE
    static Serial *instance();
#else
    explicit Serial(QObject *parent = nullptr);
#endif

    QStringList findPort();

    bool open(QString port, quint64 baud = 9600);
    void close(){   serial->close();    }
    bool isOpen(){  return serial->isOpen();    }

    qint64 sendData(QByteArray data);
    qint64 sendData(QString data);

signals:
    void haveReceive(QByteArray data);
    void sendDataShow(QString data,bool isOk);
private:
#ifdef IS_INSTANCE
    static Serial* mPtr;
    explicit Serial(QObject *parent = nullptr);
#endif
    QSerialPort *serial;

};


#endif // SERIAL_H
